package com.dayaokeji.rhythmschoolstudent.client.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;

import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.CommonWebClientFragment;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseActivity;

import butterknife.BindView;

public class AppHelperActivity extends BaseActivity {

    private static final String HELPER_URL = "http://www.jiantuokeji.com/LvDongXiaoYuan/m/article_category.php?id=1";
    private static final String FRAGMENT_TAG = "web_tag";

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    private CommonWebClientFragment webClientFragment;

    public static void navigation(Context context) {
        Intent intent = new Intent(context, AppHelperActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_helper);
        setSupportActionBar(toolbar);
        init();
    }

    private void init() {
        setupView();
    }

    private void setupView() {
        webClientFragment = (CommonWebClientFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
        if (webClientFragment == null) {
            webClientFragment = CommonWebClientFragment.newInstance(HELPER_URL);
        }
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_content, webClientFragment,FRAGMENT_TAG).commit();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
       if (webClientFragment != null && webClientFragment.onBack(keyCode,event)) {
           return true;
       }else{
           return super.onKeyDown(keyCode, event);
       }
    }
}
